#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
检查用户列表和姓名显示
"""

import sys
import os

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

from gt_lms.system.lms_system import LMSSystem
from gt_lms.ui.cli import CLI

def check_user_list():
    """检查用户列表和姓名显示"""
    system = LMSSystem()
    
    # 初始化系统
    if not system.initialize():
        print("系统初始化失败")
        return
    
    # 获取所有用户
    users = system.user_manager.get_all_users()
    
    print(f"系统中共有 {len(users)} 个用户")
    print("\n用户列表:")
    print("-" * 80)
    
    # 检查每个用户的信息
    for user in users:
        user_id = user.user_id
        name = user.get_name()
        email = user.email
        role = user.get_role()
        
        # 检查是否有"测试学生"被截断为"测试学"的情况
        if "测试学生" in name and len(name) < len("测试学生"):
            print(f"⚠️ 发现截断问题: {user_id} - {name}")
        elif "测试学生" in name:
            print(f"✓ 测试学生: {user_id} - {name}")
        else:
            print(f"  普通用户: {user_id} - {name}")
            
        print(f"    邮箱: {email}, 角色: {role}")
        
        # 检查用户ID为"1"、"2"、"3"、"4"的无效测试数据
        if user_id in ["1", "2", "3", "4"]:
            print(f"    ⚠️ 无效测试数据: 用户ID为数字")
    
    print("\n" + "-" * 80)
    
    # 检查是否有"测试学生"被截断为"测试学"的情况
    truncated_users = []
    for user in users:
        name = user.get_name()
        if "测试学" in name and len(name) < len("测试学生"):
            truncated_users.append((user.user_id, name))
    
    if truncated_users:
        print("\n⚠️ 发现姓名被截断的用户:")
        for user_id, name in truncated_users:
            print(f"  {user_id}: {name}")
    else:
        print("\n✓ 未发现姓名被截断的用户")
    
    # 检查无效测试数据
    invalid_users = []
    for user in users:
        user_id = user.user_id
        if user.user_id in ["1", "2", "3", "4"]:
            invalid_users.append(user.user_id)
    
    if invalid_users:
        print(f"\n⚠️ 发现 {len(invalid_users)} 个无效测试数据:")
        for user_id in invalid_users:
            print(f"  {user_id}")
    else:
        print("\n✓ 未发现无效测试数据")

if __name__ == "__main__":
    check_user_list()